﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Travel.DAL
{
	/// <summary>
	/// 数据访问类:route_content
	/// </summary>
	public partial class route_content
	{
		public route_content()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from route_content");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Travel.Model.route_content model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into route_content(");
			strSql.Append("id,route_id,feature,route_contains,rout_not_contains,own_expense,shopping_area,service,friend_ship_tip,visa_notice,r_content,created_on,created_by,changed_on,changed_by)");
			strSql.Append(" values (");
			strSql.Append("@id,@route_id,@feature,@route_contains,@rout_not_contains,@own_expense,@shopping_area,@service,@friend_ship_tip,@visa_notice,@r_content,@created_on,@created_by,@changed_on,@changed_by)");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@route_id", SqlDbType.Int,4),
					new SqlParameter("@feature", SqlDbType.NVarChar),
					new SqlParameter("@route_contains", SqlDbType.NVarChar),
					new SqlParameter("@rout_not_contains", SqlDbType.NVarChar),
					new SqlParameter("@own_expense", SqlDbType.NVarChar),
					new SqlParameter("@shopping_area", SqlDbType.NVarChar),
					new SqlParameter("@service", SqlDbType.NVarChar),
					new SqlParameter("@friend_ship_tip", SqlDbType.NVarChar),
					new SqlParameter("@visa_notice", SqlDbType.NVarChar),
					new SqlParameter("@r_content", SqlDbType.NVarChar),
					new SqlParameter("@created_on", SqlDbType.DateTime),
					new SqlParameter("@created_by", SqlDbType.NVarChar,50),
					new SqlParameter("@changed_on", SqlDbType.DateTime),
					new SqlParameter("@changed_by", SqlDbType.NVarChar,50)};
			parameters[0].Value = Guid.NewGuid();
			parameters[1].Value = model.route_id;
			parameters[2].Value = model.feature;
			parameters[3].Value = model.route_contains;
			parameters[4].Value = model.rout_not_contains;
			parameters[5].Value = model.own_expense;
			parameters[6].Value = model.shopping_area;
			parameters[7].Value = model.service;
			parameters[8].Value = model.friend_ship_tip;
			parameters[9].Value = model.visa_notice;
			parameters[10].Value = model.r_content;
			parameters[11].Value = model.created_on;
			parameters[12].Value = model.created_by;
			parameters[13].Value = model.changed_on;
			parameters[14].Value = model.changed_by;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Travel.Model.route_content model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update route_content set ");
			strSql.Append("route_id=@route_id,");
			strSql.Append("feature=@feature,");
			strSql.Append("route_contains=@route_contains,");
			strSql.Append("rout_not_contains=@rout_not_contains,");
			strSql.Append("own_expense=@own_expense,");
			strSql.Append("shopping_area=@shopping_area,");
			strSql.Append("service=@service,");
			strSql.Append("friend_ship_tip=@friend_ship_tip,");
			strSql.Append("visa_notice=@visa_notice,");
			strSql.Append("r_content=@r_content,");
			strSql.Append("created_on=@created_on,");
			strSql.Append("created_by=@created_by,");
			strSql.Append("changed_on=@changed_on,");
			strSql.Append("changed_by=@changed_by");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@route_id", SqlDbType.Int,4),
					new SqlParameter("@feature", SqlDbType.NVarChar),
					new SqlParameter("@route_contains", SqlDbType.NVarChar),
					new SqlParameter("@rout_not_contains", SqlDbType.NVarChar),
					new SqlParameter("@own_expense", SqlDbType.NVarChar),
					new SqlParameter("@shopping_area", SqlDbType.NVarChar),
					new SqlParameter("@service", SqlDbType.NVarChar),
					new SqlParameter("@friend_ship_tip", SqlDbType.NVarChar),
					new SqlParameter("@visa_notice", SqlDbType.NVarChar),
					new SqlParameter("@r_content", SqlDbType.NVarChar),
					new SqlParameter("@created_on", SqlDbType.DateTime),
					new SqlParameter("@created_by", SqlDbType.NVarChar,50),
					new SqlParameter("@changed_on", SqlDbType.DateTime),
					new SqlParameter("@changed_by", SqlDbType.NVarChar,50),
					new SqlParameter("@id", SqlDbType.UniqueIdentifier,16)};
			parameters[0].Value = model.route_id;
			parameters[1].Value = model.feature;
			parameters[2].Value = model.route_contains;
			parameters[3].Value = model.rout_not_contains;
			parameters[4].Value = model.own_expense;
			parameters[5].Value = model.shopping_area;
			parameters[6].Value = model.service;
			parameters[7].Value = model.friend_ship_tip;
			parameters[8].Value = model.visa_notice;
			parameters[9].Value = model.r_content;
			parameters[10].Value = model.created_on;
			parameters[11].Value = model.created_by;
			parameters[12].Value = model.changed_on;
			parameters[13].Value = model.changed_by;
			parameters[14].Value = model.id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from route_content ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from route_content ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Travel.Model.route_content GetModel(Guid id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,route_id,feature,route_contains,rout_not_contains,own_expense,shopping_area,service,friend_ship_tip,visa_notice,r_content,created_on,created_by,changed_on,changed_by from route_content ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = id;

			Travel.Model.route_content model=new Travel.Model.route_content();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id= new Guid(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["route_id"]!=null && ds.Tables[0].Rows[0]["route_id"].ToString()!="")
				{
					model.route_id=int.Parse(ds.Tables[0].Rows[0]["route_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["feature"]!=null && ds.Tables[0].Rows[0]["feature"].ToString()!="")
				{
					model.feature=ds.Tables[0].Rows[0]["feature"].ToString();
				}
				if(ds.Tables[0].Rows[0]["route_contains"]!=null && ds.Tables[0].Rows[0]["route_contains"].ToString()!="")
				{
					model.route_contains=ds.Tables[0].Rows[0]["route_contains"].ToString();
				}
				if(ds.Tables[0].Rows[0]["rout_not_contains"]!=null && ds.Tables[0].Rows[0]["rout_not_contains"].ToString()!="")
				{
					model.rout_not_contains=ds.Tables[0].Rows[0]["rout_not_contains"].ToString();
				}
				if(ds.Tables[0].Rows[0]["own_expense"]!=null && ds.Tables[0].Rows[0]["own_expense"].ToString()!="")
				{
					model.own_expense=ds.Tables[0].Rows[0]["own_expense"].ToString();
				}
				if(ds.Tables[0].Rows[0]["shopping_area"]!=null && ds.Tables[0].Rows[0]["shopping_area"].ToString()!="")
				{
					model.shopping_area=ds.Tables[0].Rows[0]["shopping_area"].ToString();
				}
				if(ds.Tables[0].Rows[0]["service"]!=null && ds.Tables[0].Rows[0]["service"].ToString()!="")
				{
					model.service=ds.Tables[0].Rows[0]["service"].ToString();
				}
				if(ds.Tables[0].Rows[0]["friend_ship_tip"]!=null && ds.Tables[0].Rows[0]["friend_ship_tip"].ToString()!="")
				{
					model.friend_ship_tip=ds.Tables[0].Rows[0]["friend_ship_tip"].ToString();
				}
				if(ds.Tables[0].Rows[0]["visa_notice"]!=null && ds.Tables[0].Rows[0]["visa_notice"].ToString()!="")
				{
					model.visa_notice=ds.Tables[0].Rows[0]["visa_notice"].ToString();
				}
				if(ds.Tables[0].Rows[0]["r_content"]!=null && ds.Tables[0].Rows[0]["r_content"].ToString()!="")
				{
					model.r_content=ds.Tables[0].Rows[0]["r_content"].ToString();
				}
				if(ds.Tables[0].Rows[0]["created_on"]!=null && ds.Tables[0].Rows[0]["created_on"].ToString()!="")
				{
					model.created_on=DateTime.Parse(ds.Tables[0].Rows[0]["created_on"].ToString());
				}
				if(ds.Tables[0].Rows[0]["created_by"]!=null && ds.Tables[0].Rows[0]["created_by"].ToString()!="")
				{
					model.created_by=ds.Tables[0].Rows[0]["created_by"].ToString();
				}
				if(ds.Tables[0].Rows[0]["changed_on"]!=null && ds.Tables[0].Rows[0]["changed_on"].ToString()!="")
				{
					model.changed_on=DateTime.Parse(ds.Tables[0].Rows[0]["changed_on"].ToString());
				}
				if(ds.Tables[0].Rows[0]["changed_by"]!=null && ds.Tables[0].Rows[0]["changed_by"].ToString()!="")
				{
					model.changed_by=ds.Tables[0].Rows[0]["changed_by"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,route_id,feature,route_contains,rout_not_contains,own_expense,shopping_area,service,friend_ship_tip,visa_notice,r_content,created_on,created_by,changed_on,changed_by ");
			strSql.Append(" FROM route_content ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,route_id,feature,route_contains,rout_not_contains,own_expense,shopping_area,service,friend_ship_tip,visa_notice,r_content,created_on,created_by,changed_on,changed_by ");
			strSql.Append(" FROM route_content ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM route_content ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from route_content T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "route_content";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

